
#include "stdafx.h"
#include <allegro5/allegro_primitives.h>
#include "TankTurret.h"

TankTurret::TankTurret(const char * modelName):
BaseComponent(modelName) {
  // Bouml preserved body begin 000218FB
  // Bouml preserved body end 000218FB
}

TankTurret::~TankTurret(){
  // Bouml preserved body begin 0002197B
  // Bouml preserved body end 0002197B
}

bool TankTurret::AttachGun(const _TankGun & tankGun, char slot) {
  // Bouml preserved body begin 0001FBFB

	if ( slot >= _maxGuns )
	{
		return false;
	}

	_guns[ slot] = tankGun;

	return true;
  // Bouml preserved body end 0001FBFB
}

void TankTurret::Assemble() {
  // Bouml preserved body begin 000219FB
	const char kBase1[] = "base1";

	if ( !_modelName.compare( kBase1 ) ) {		
		_maxGuns = 1;
		_guns.resize( 1 ); //14.65

		float shape[] = { -26.40, 38.75, 26.40, 38.75, 26.40, -27.10, -26.40, -27.10 };
		LoadFigure( 4, shape );
		BaseComponent::point turretCenter = { 0, 0 };

		_gunSlots.clear();
		_gunSlots.resize( 1 );
		_gunSlots[ 0] =  turretCenter;
	} else {
		_maxGuns = 0;
		_guns.resize( 0 );
	}
  // Bouml preserved body end 000219FB
}

//Draws object in given position

void TankTurret::DrawAt(const BaseComponent::point & position) {
  // Bouml preserved body begin 000269FB
	BaseComponent::DrawAt( position );
	
	ALLEGRO_TRANSFORM current, toUse;
	al_copy_transform( &current, al_get_current_transform() );
	al_identity_transform( &toUse );	
	al_rotate_transform( &toUse, _angle );
	al_translate_transform( &toUse, position.x, position.y );
	al_compose_transform( &toUse, &current );
	al_use_transform(&toUse);
	
	for ( int i = 0;  i < _guns.size(); i++ ) {
		_guns[ i]->DrawAt( _gunSlots[ i] );
	}

	al_use_transform( &current );
  // Bouml preserved body end 000269FB
}

